﻿using System;
using System.Reflection;
using System.Web.Security;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace Sfd.WebApp.Utilities
{
    public class AzureMembershipProvider : SqlMembershipProvider
    {
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            base.Initialize(name, config);

            if (!RoleEnvironment.IsAvailable)
                throw new NotSupportedException("AzureMembershipProvider est seulement disponible dans un environnement Azure");

            var connectionStringField = GetType().BaseType.GetField("_sqlConnectionString", BindingFlags.Instance | BindingFlags.NonPublic);
            connectionStringField.SetValue(this, RoleEnvironment.GetConfigurationSettingValue("ProjectsDb"));
        }
    }
}